<template>
	<view>
		<view class="head_box">
			<view class="add-address-box " v-if="address.addressId == '-1' || !address.addressId"
				@tap="jump('/pages/address/addressList')">
				<view class="box-bg flex justify-between align-center padding">
					<text class="select-notice">请选择收货地址</text>
					<text class="cuIcon-right"></text>
				</view>
			</view>
			<view class="address-list" v-else @tap="jump('/pages/address/addressList')">
				<view class="top flex justify-start">
					<text class="name">{{ address.username }}</text>
					<text class="phone">{{ address.tel }}</text>
					<text class="tag" v-if="address.isDefault == 'T'">默认</text>
				</view>
				<view class="detail flex justify-between">
					<view class="address">{{ address.address }}</view>
					<text class="cuIcon-right"></text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserAddress,
	} from '../../api/user/userApi.js'
	export default {
		name: "goodsAddress",
		data() {
			return {
				address: {

				}
			};
		},
		created() {
			this.getDefaultAddress();
			let _that = this;
			uni.$on('userAddress',function(_address){
				_that.address = _address;
			})
		},
		methods: {
			getUserAddress:function(){
				return this.address;
			},
			getDefaultAddress: function() {
				let that = this;
				getUserAddress({
						userId: this.vc.getCurrentUser().userId,
						isDefault: 'T',
						page: 1,
						row: 1
					})
					.then((_data) => {
						if (_data.data != null && _data.data.length > 0) {
							that.address = _data.data[0]
						}
					})
			},
			jump: function(path) {
				this.vc.navigateTo({
					url: path
				})
			},
		}
	}
</script>

<style lang="scss">
	.add-address-box {
		height: 100rpx;
		background: #fff;
		position: relative;

		.address-bg {
			position: absolute;
			bottom: 0;
			height: 8rpx;
			width: 100%;
		}

		.select-notice {
			font-weight: 400;
			color: rgba(153, 153, 153, 1);
			line-height: 40rpx;
		}
	}

	.address-list {
		padding: 40rpx;
		background: #fff;

		position: relative;

		.address-bg {
			position: absolute;
			bottom: 0;
			height: 8rpx;
			width: 750rpx;
			left: 50%;
			transform: translateX(-50%);
		}

		.name,
		.phone {
			font-size: 30rpx;
			font-weight: 500;
		}

		.phone {
			margin: 0 20rpx;
		}

		.tag {
			background: rgba(233, 191, 113, 0.2);
			border-radius: 6rpx;
			padding: 0 16rpx;
			line-height: 38rpx;
			color: #a8700d;
			font-size: 22rpx;
		}

		.detail {
			.address {
				margin-top: 25rpx;
				width: 543rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: rgba(153, 153, 153, 1);
				line-height: 40rpx;
			}
		}
	}
</style>
